package com.guowen.myaccount;

import static java.lang.Math.abs;
import static java.lang.Math.min;

import com.guowen.myaccount.db.AccountBean;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Generator {
    public List<AccountBean> generate(int sImageId,int kind,String type, int l, int r, int total){
        List<AccountBean> list = new ArrayList<>();
        Random random = new Random(System.nanoTime());
        int len = r-l+1;
        int sum = 0;
        int cnt = 0;
        String account;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date date = new Date(System.currentTimeMillis());// new Date()为获取当前系统时间
        while(sum < total){
            if(random.nextBoolean()) account = "微信";
            else account = "支付宝";
            int price = min(l + abs(random.nextInt())%len,total-sum);
            sum += price;
            int hour = 8+abs(random.nextInt())%16;
            int minutes = abs(random.nextInt())%60;
            int month = date.getMonth()+1;
            int day = 1+abs(random.nextInt()%(date.getDate()-1));
            String time = String.format("%d年%d月%d日 %d:%d",2021,month,day,hour,minutes);
            list.add(new AccountBean(cnt++, sImageId, kind, type, "", time, account, price, 2021, month, day));
        }
        list.sort((a,b)->{
            if(a.getYear() == b.getYear()){
                if(a.getMonth() == b.getMonth()){
                    return b.getDay() - a.getDay();
                }
                return b.getMonth() - a.getMonth();
            }
            return 1;
        });

        return list;
    }
}
